package world.ztomorrow.author.config;

import lombok.RequiredArgsConstructor;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.DispatcherServlet;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import world.ztomorrow.author.interceptor.AuthorInterceptor;

@Configuration
@ConditionalOnClass(DispatcherServlet.class)
@RequiredArgsConstructor
public class AuthorConfig implements WebMvcConfigurer {

    private final AuthorInterceptor authorInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(authorInterceptor)
                .addPathPatterns("/author/**")
                .excludePathPatterns(
                        "/author/status",
                        "/author/register"
                )
                .order(2);
    }
}
